﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class DamageRecountInfo {
    public uint skillCastID = 0;
    public DRDmgType dmgType = DRDmgType.None;
    public float damageTotal = 0f;
    public float healthTotal = 0f;

    public void AddDamage(float dmg) {
        damageTotal += dmg;
        dmgType &= DRDmgType.Damage;
    }
    public void AddHealth(float heal) {
        healthTotal += heal;
        dmgType &= DRDmgType.Health;
    }

}
public enum DRDmgType {
    None = 0,
    Damage = 1,
    Health = 2,
    Both = 4,   //既有伤害也有治疗
}

public class DamageRecount {
    static DamageRecount m_ins = new DamageRecount();

    //<skillCastID, damageInfo>
    public Dictionary<uint, DamageRecountInfo> registSkills = new Dictionary<uint, DamageRecountInfo>();


    public static DamageRecount Share() {
        return m_ins;
    }

    DamageRecountInfo obtainDRinfo(uint skillCastID) {
        DamageRecountInfo result = null;
        if(false == registSkills.TryGetValue(skillCastID, out result)) {
            result = new DamageRecountInfo();
            result.skillCastID = skillCastID;
            registSkills.Add(skillCastID, result);
        }

        return result;
    }
    DamageRecountInfo getDRinfo(uint skillCastID) {
        DamageRecountInfo result = null;
        registSkills.TryGetValue(skillCastID, out result);
        return result;
    }


    public DamageRecountInfo RegistSkillDmgRecount(uint skillCastID) {
        Debug.LogFormat("[RegistSkillDmgRecount] skillCastID:{0}", skillCastID);
        return obtainDRinfo(skillCastID);
    }

    public DamageRecountInfo GetDRinfo(uint skillCastID) {
        return getDRinfo(skillCastID);
    }

    public float GetDRDamage(uint skillCastID) {
        var dr = getDRinfo(skillCastID);
        if(dr == null) return 0;

        return dr.damageTotal;
    }
    public float GetDRHeal(uint skillCastID) {
        var dr = getDRinfo(skillCastID);
        if(dr == null) return 0;

        return dr.healthTotal;
    }

    public void AddDamage(uint skillCastID, float dmg) {
        var dr = getDRinfo(skillCastID);
        if(dr == null) return;

        dr.damageTotal += dmg;
        dr.dmgType &= DRDmgType.Damage;
    }
    public void AddHealth(uint skillCastID, float heal) {
        var dr = getDRinfo(skillCastID);
        if(dr == null) return;

        dr.healthTotal += heal;
        dr.dmgType &= DRDmgType.Health;
    }
}
